package com.itheima.tlias.controller;

import com.itheima.tlias.pojo.Emp;
import com.itheima.tlias.pojo.LogInfo;
import com.itheima.tlias.pojo.Result;
import com.itheima.tlias.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LoginController {
	@Autowired
	private EmpService empService;

	@PostMapping("/login")
	public Result logIn(@RequestBody Emp emp) {
		log.info("用户登录：{}", emp);
		LogInfo logInfo = empService.login(emp);
		if (logInfo != null) {
			return Result.success(logInfo);
		}
		return Result.error("用户名或密码错误");
	}
}
